# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.

project(apphost)
set(DOTNET_PROJECT_NAME "apphost")

# Add RPATH to the apphost binary that allows using local copies of shared libraries
# dotnet core depends on for special scenarios when system wide installation of such
# dependencies is not possible for some reason.
# This cannot be enabled for MacOS (Darwin) since its RPATH works in a different way,
# doesn't apply to libraries loaded via dlopen and most importantly, it is not transitive.
if (NOT CLR_CMAKE_TARGET_DARWIN)
    set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
    set(CMAKE_INSTALL_RPATH "\$ORIGIN/netcoredeps")
endif()

set(SKIP_VERSIONING 1)

set(SOURCES
    ./bundle/file_entry.cpp
    ./bundle/manifest.cpp
    ./bundle/header.cpp
    ./bundle/marker.cpp
    ./bundle/reader.cpp
    ./bundle/extractor.cpp
    ./bundle/runner.cpp
    ./bundle/dir_utils.cpp
)

set(HEADERS
    ./bundle/file_type.h
    ./bundle/file_entry.h
    ./bundle/manifest.h
    ./bundle/header.h
    ./bundle/marker.h
    ./bundle/reader.h
    ./bundle/extractor.h
    ./bundle/runner.h
    ./bundle/dir_utils.h
)

if(CLR_CMAKE_TARGET_WIN32)
    list(APPEND SOURCES
        apphost.windows.cpp)

    list(APPEND HEADERS
        apphost.windows.h)
endif()

include(../exe.cmake)

add_definitions(-DFEATURE_APPHOST=1)

# Disable manifest generation into the file .exe on Windows
if(CLR_CMAKE_TARGET_WIN32)
    set_property(TARGET ${PROJECT_NAME} PROPERTY
            LINK_FLAGS "/MANIFEST:NO"
        )
endif()

# Specify non-default Windows libs to be used for Arm/Arm64 builds
if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64))
    target_link_libraries(apphost Advapi32.lib shell32.lib)
endif()
